﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;

namespace Transport
{
    public partial class HideCarsDetail : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected string GetService(string maDichVu)
        {
            string html = null;
            DichVuControl dv = new DichVuControl();
            List<dich_vu> list = dv.listAll();
            foreach (dich_vu dichVu in list)
            {
                if (maDichVu == dichVu.id_dich_vu)
                    html += "<li><div><a class=\"selected\" href=\"./HireCars.aspx?madichvu=" + dichVu.id_dich_vu + "\">" + dichVu.ten_dich_vu + "</a></div></li>";
                else
                    html += "<li><div><a href=\"./HireCars.aspx?madichvu=" + dichVu.id_dich_vu + "\">" + dichVu.ten_dich_vu + "</a></div></li>";
            }
            return html;
        }
        protected void AddToCart(string idDichVu,string maSoXe,int phuongThucLai,string mien,string tungay,string denngay,string malotrinh,string giodon,string diadiemdon)
        {
            BangGiaNgayAdminControl bangGiaNgay = new BangGiaNgayAdminControl();
            BangGiaLoTrinhAdminControl bangGiaLoTrinh = new BangGiaLoTrinhAdminControl();
            DateTime tuNgay = Convert.ToDateTime(tungay);
            DateTime denNgay = Convert.ToDateTime(denngay);
            TimeSpan gioDon = TimeSpan.Parse(giodon);
            TimeSpan span;
            TimeSpan.TryParse(giodon.Replace("m", "").Replace("h", ""), out span);
            DichVuControl dichVuControl = new DichVuControl();
            if (dichVuControl.findByID(idDichVu) != null)
            {
                DichVuControl dv = new DichVuControl();
                switch (idDichVu)
                {
                    case "0":
                        {
                            if (bangGiaLoTrinh.findByCarID(maSoXe).Count > 0)
                            {
                                XeControl xeCtrl = new XeControl();
                                BGTLTentity bangGiaLT = xeCtrl.listAllByIDCar(maSoXe);
                                ChiTietDatXeControl ctr = new ChiTietDatXeControl();
                                
                                int giaTien = ctr.calculateFeeWithIDCarNSerVice(maSoXe, idDichVu, tuNgay, denNgay, phuongThucLai, malotrinh);
                                CartDTO cart = new CartDTO(bangGiaLT.Songay,maSoXe, bangGiaLT.Ten_thuong_hieu, phuongThucLai, mien, idDichVu, giaTien, bangGiaLT.So_cho, tuNgay, denNgay, malotrinh, dv.findByID(idDichVu).ten_dich_vu, span, diadiemdon);
                                ShoppingCart.Instance.AddItem(cart);
                                Response.Redirect("Orders.aspx");
                            }
                        }
                        break;
                    default:
                        {
                            if (bangGiaNgay.findByCarNumber(maSoXe).Count > 0)
                            {
                                BangGiaTrongNgayControl bangGia = new BangGiaTrongNgayControl();
                                BangGiaTrongNgayNew carInfo = bangGia.GetBangGiaByIDCar(maSoXe);
                                ChiTietDatXeControl ctr = new ChiTietDatXeControl();
                                int giaTien = ctr.calculateFeeWithIDCarNSerVice(maSoXe, idDichVu, tuNgay, denNgay, phuongThucLai, malotrinh);
                                CartDTO cart = new CartDTO(0,maSoXe, carInfo.HieuXe, phuongThucLai, mien, idDichVu, giaTien, carInfo.LoaiXe, tuNgay, denNgay, malotrinh, dv.findByID(idDichVu).ten_dich_vu, span, diadiemdon);
                                ShoppingCart.Instance.AddItem(cart);
                                Response.Redirect("Orders.aspx");
                            }
                        }
                        break;
                }
            }
        }
        protected string getDetailByService(string idService, string idCar,string malotrinh)
        {
            BangGiaNgayAdminControl bangGiaNgay = new BangGiaNgayAdminControl();
            BangGiaLoTrinhAdminControl bangGiaLoTrinh = new BangGiaLoTrinhAdminControl();
            DichVuControl dichVuControl = new DichVuControl();
            XeControl banggiaLT = new XeControl();
            string html = null;
            if (dichVuControl.findByID(idService) != null)
            {
                switch (idService)
                {
                    case "0":
                        {
                            if (null != bangGiaLoTrinh.findByCarNumberAndRouteID(idCar, malotrinh))
                            {
                                BGTLTentity ctrLT = banggiaLT.listAllByIDCar(idCar);
                                html += "<div class=\"detail-imgproduct\">"
                            + "<img class=\"detail_img\" src=\"template/hktransport/products/2012-28-12.jpg\" width=\"350px\" height=\"400px\""
                                + "alt=\"audi-2012\">"
                        + "</div>"
                       + "<div class=\"detail-text\">"
                                + "<h1>"
                                    + "" + ctrLT.Ten_thuong_hieu + "</h1>"
                                + "<div id=\"car_text_detail\">"
                                    + "<p style=\"text-align: justify\" class=\"MsoNormal\">"
                                        + "<span style=\"font-size: 10pt; line-height: 115%\">Một vài thông tin về Audi 2012</span>"
                                    + "</p>"
                                    + "<form name=\"addtocartfrm\" id=\"addtocartfrm\" method=\"post\">"
                                        + "<input type=\"hidden\" name=\"madichvu\" value=\"" + idService + "\" />"
                                         + "<input type=\"hidden\" name=\"masoxe\" value=\"" + idCar + "\" />"
                                         + "<input type=\"hidden\" name=\"malotrinh\" value=\"" + ctrLT.MaLoTrinh + "\" />"
                                        + "<div class=\"detail_row\">"
                                            + "<div class=\"detail_title\">Giá thuê ngày</div>"
                                            + "<div class=\"detail_content\"><h2>" + String.Format(CultureInfo.CreateSpecificCulture("en-US"), "{0:c}", ctrLT.Gia_tien) + "</h2></div>"
                                        + "</div>"
                                           + "<div class=\"detail_row\">"
                                                + "<div class=\"detail_title\">Chi phí vượt Km</div>"
                                                + "<div class=\"detail_content\"><h2>" + String.Format(CultureInfo.CreateSpecificCulture("en-US"), "{0:c}", ctrLT.Chi_phi_vuot_km) + "</h2></div>"
                                            + "</div>"
                                             + "<div class=\"detail_row\">"
                                                + "<div class=\"detail_title\">Hãng xe</div>"
                                                + "<div class=\"detail_content\">" + ctrLT.HangXe + "</div>"
                                            + "</div>"
                                            + "<div class=\"detail_row\">"
                                                + "<div class=\"detail_title\">Loại xe</div>"
                                                + "<div class=\"detail_content\">" + ctrLT.So_cho + " chỗ</div>"
                                            + "</div>"
                                             + "<div class=\"detail_row\">"
                                                + "<div class=\"detail_title\">Lộ trình</div>"
                                                + "<div class=\"detail_content\">" + ctrLT.Ten_lo_trinh + "</div>"
                                            + "</div>"
                                            + "<div class=\"detail_row\">"
                                                + "<div class=\"detail_title\">Số KM</div>"
                                                + "<div class=\"detail_content\">" + ctrLT.SoKM + " KM</div>"
                                            + "</div>"
                                             + "<div class=\"detail_row\">"
                                                + "<div class=\"detail_title\">Số ngày</div>"
                                                + "<div class=\"detail_content\">" + ctrLT.Songay + " ngày</div>"
                                            + "</div>"
                                             + "<div class=\"detail_row\">"
                                            + "<span class=\"detail_title\">*Ngày đi</span>"
                                            + "<div class=\" detail_content\"><input type=\"text\" class=\"required\" name=\"tungay\" size='15' id=\"tungay\"/></div>"
                                        + "</div>"
                                          + "<div class=\"detail_row\">"
                                            + "<span class=\"detail_title\">*Giờ đón</span>"
                                            + "<div class=\" detail_content\"><input type=\"text\" class=\"required\" name=\"giodon\" size='15' id=\"giodon\"/></div>"
                                        + "</div>"
                                         + "<div class=\"detail_row\">"
                                            + "<span class=\"detail_title\">*Địa điểm đón</span>"
                                            + "<div class=\" detail_content\"><input type=\"text\" class=\"required\" name=\"diadiemdon\" size='15' id=\"diadiemdon\"/></div>"
                                        + "</div>"
                            + "<div id=\"add_to_cart_submit_wrapper\">"
                                + "<div id=\"add_to_cart_submit\">"
                                    + "<input type=\"submit\" class=\"readmore\" name=\"add_to_cart\" id=\"add_to_cart\" value=\"Thêm vào giỏ hàng\" />"
                                    + "</div>"
                            + "</div>"
                         + "</form></div></div>";
                            }
                        }
                        break;
                    default:
                        {
                            if (bangGiaNgay.findByCarNumber(idCar).Count > 0)
                            {
                                BangGiaTrongNgayControl bangGia = new BangGiaTrongNgayControl();
                                BangGiaTrongNgayNew carInfo = bangGia.GetBangGiaByIDCar(idCar);
                                html += "<div class=\"detail-imgproduct\">"
                                + "<img class=\"detail_img\" src=\"template/hktransport/products/2012-28-12.jpg\" width=\"350px\" height=\"400px\""
                                    + "alt=\"audi-2012\">"
                            + "</div>"
                            + "<div class=\"detail-text\">"
                                + "<h1>"
                                    + "" + carInfo.HieuXe+ "</h1>"
                                + "<div id=\"car_text_detail\">"
                                    + "<p style=\"text-align: justify\" class=\"MsoNormal\">"
                                        + "<span style=\"font-size: 10pt; line-height: 115%\">Một vài thông tin về Audi 2012</span>"
                                    + "</p>"
                                    + "<form name=\"addtocartfrm\" id=\"addtocartfrm\" method=\"post\">"
                                        + "<input type=\"hidden\" name=\"madichvu\" value=\""+idService+"\" />"
                                         + "<input type=\"hidden\" name=\"masoxe\" value=\""+idCar+"\" />"
                                         + "<input type=\"hidden\" name=\"malotrinh\" value=\"HKTRANSPORT\" />"
                                        + "<div class=\"detail_row\">"
                                            + "<div class=\"detail_title\">Giá thuê ngày</div>"
                                            + "<div class=\"detail_content\"><h2>" + String.Format(CultureInfo.CreateSpecificCulture("en-US"), "{0:c}", carInfo.GiaTien) + "</h2></div>"
                                        + "</div>"
                                        + "<div class=\"detail_row\">"
                                            + "<div class=\"detail_title\">Giá ngoài giờ</div>"
                                            + "<div class=\"detail_content\"><h2>" + String.Format(CultureInfo.CreateSpecificCulture("en-US"), "{0:c}", carInfo.GiaNgoaiGio) + "/giờ</h2></div>"
                                        + "</div>";
                                if (idService == "1")
                                    html += "<div class=\"detail_row\">"
                                     + "<div class=\"detail_title\">Giá trang trí</div>"
                                     + "<div class=\"detail_content\"><h2>" + String.Format(CultureInfo.CreateSpecificCulture("en-US"), "{0:c}", carInfo.GiaTrangTri) + "</h2></div>"
                                 + "</div>";
                                html += "<div class=\"detail_row\">"
                                                + "<div class=\"detail_title\">Chi phí tài xế</div>"
                                                + "<div class=\"detail_content\"><h2>" + String.Format(CultureInfo.CreateSpecificCulture("en-US"), "{0:c}", carInfo.ChiPhiTaiXe) + "</h2></div>"
                                            + "</div>"
                                            + "<div class=\"detail_row\">"
                                                + "<div class=\"detail_title\">Phí lưu đêm</div>"
                                                + "<div class=\"detail_content\"><h2>" + String.Format(CultureInfo.CreateSpecificCulture("en-US"), "{0:c}", carInfo.PhiLuuDem) + "</h2></div>"
                                            + "</div>"
                                             + "<div class=\"detail_row\">"
                                                + "<div class=\"detail_title\">Hãng xe</div>"
                                                + "<div class=\"detail_content\">" + carInfo.HangXe + "</div>"
                                            + "</div>"
                                            + "<div class=\"detail_row\">"
                                                + "<div class=\"detail_title\">Loại xe</div>"
                                                + "<div class=\"detail_content\">" + carInfo.LoaiXe + " chỗ</div>"
                                            + "</div>"
                                            + "<div class=\"detail_row\">"
                                    + "</div>";
                                if (idService != "1")
                                    html += "<div class=\"detail_row\">"
                                    + "<div class=\"detail_title\">Phương thức lái</div>"
                                    + "<div class=\"detail_content\"><select name=\"phuongthuclai\">"
                                            + "<option value=\"0\">Không tài xế</option>"
                                            + "<option value=\"1\">Có tài xế</option>"
                                    + "</select></div>"
                                + "</div>";
                                else
                                    html += "<input type=\"hidden\" name=\"phuongthuclai\" id=\"phuongthuclai\" value='1'/>";

                                html += "<div class=\"detail_row\">"
                                    + "<div class=\"detail_title\">Miền</div>"
                                    + "<div class=\"detail_content\"><select name=\"mien\">";
                                MienControl mien = new MienControl();
                                List<mien> list = mien.listAll();
                                foreach (mien item in list)
                                {
                                    html +="<option value=\""+item.ma_mien+"\">"+item.ten_mien+"</option>";
                                }
                                    html+= "</select></div>"
                                + "</div>"
                                + "<div class=\"detail_row\">"
                                    + "<span class=\"detail_title\">*Từ ngày</span>"
                                    + "<div class=\" detail_content\"><input type=\"text\" class=\"required\" name=\"tungay\" size='15' id=\"tungay\"/></div>"
                                + "</div>"
                                + "<div class=\"detail_row\">"
                                    + "<span class=\"detail_title\">*Đến ngày</span>"
                                    + "<div class=\" detail_content\"><input type=\"text\" class=\"required\" name=\"denngay\" size='15' id=\"denngay\"/></div>"
                                + "</div>"
                                 + "<div class=\"detail_row\">"
                                            + "<span class=\"detail_title\">*Giờ đón</span>"
                                            + "<div class=\" detail_content\"><input type=\"text\" class=\"required\" name=\"giodon\" size='10' id=\"giodon\"/></div>"
                                        + "</div>"
                                         + "<div class=\"detail_row\">"
                                            + "<span class=\"detail_title\">*Địa điểm đón</span>"
                                            + "<div class=\" detail_content\"><input type=\"text\" class=\"required\" name=\"diadiemdon\" size='15' id=\"diadiemdon\"/></div>"
                                        + "</div>"
                                + "<div id=\"add_to_cart_submit_wrapper\">"
                                    + "<div id=\"add_to_cart_submit\">"
                                        + "<input type=\"submit\" class=\"readmore\" name=\"add_to_cart\" id=\"add_to_cart\" value=\"Thêm vào giỏ hàng\" />"
                                        + "</div>"
                                + "</div>"
                             + "</form></div></div>";
                            }
                        }
                        break;
                }
            }
            else
                html += "<h2>Not Found</h2>";
            return html;
        }
    }
}